package Page;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class DelePage {

	// 删除联系人，输入联系人姓名，根据姓名删除
	public void delePage(Statement statement) {
		JFrame jframe = new JFrame("个人通讯录系统");

		// 当关闭窗口时，退出整个程序
		jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// 设置窗口大小
		jframe.setSize(900, 300);

		// 显示窗口
		jframe.setVisible(true);

		// 创建面板
		JPanel jpanel = new JPanel();
		jframe.setContentPane(jpanel);

		// JLabel jl=new JLabel("请输入要删除联系人的姓名：",JLabel.ABORT);

		JLabel id_l = new JLabel("请输入将删除联系人的编号:");
		jpanel.add(id_l);
		JTextField id = new JTextField(20);
		jpanel.add(id);

		JButton button = new JButton("OK");
		jpanel.add(button);

		button.addActionListener((e) -> {

			String id_get = id.getText();
			// 根据Id删除联系人

			try {

				Connection conn = null;
				PreparedStatement psmt = null;

				conn = Main.getConnection();
				String sql = "DELETE FROM address_book_contact WHERE id = " + id_get + "; ";
				psmt = conn.prepareStatement(sql);
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

			// 提示信息
			JOptionPane.showMessageDialog(null, "删除编号" + id_get + "的联系人成功！");
		});

	}

}
